# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Pieter Goetschalckx <3.14.e.ter at gmail dot com>
# Contributor: Stijn Seghers (Procrat) <stijnseghers at gmail dot com>

pkgname=pylama
pkgver=7.7.1
pkgrel=9
pkgdesc="Code audit tool for python"
arch=('any')
url="https://github.com/klen/pylama"
license=('GPL3')
depends=('python-pycodestyle' 'python-pydocstyle' 'python-pyflakes' 'python-mccabe')
makedepends=('python-setuptools')
checkdepends=('python-pytest' 'git' 'mypy')
optdepends=('python-radon: radon support')
source=("$pkgname-$pkgver.tar.gz::https://github.com/klen/pylama/archive/$pkgver.tar.gz"
        pylama-pytest-6.patch::https://github.com/klen/pylama/pull/189.patch
        pylama-pyflakes-2.5.patch)
sha256sums=('acec2b80ad6a4781dc2626992b10ecac7b81be6c0145750c11688c281298f6fe'
            '6a025bb41afe783841ecb28ab6faada4be9d7b3d152f0a58970757953d343cba'
            'a236eb95ad4c835ae4bdc50950f8ede89bdb84c89726d38304f896ce553604fc')

prepare() {
  cd $pkgname-$pkgver
  patch -p1 -i ../pylama-pytest-6.patch
  patch -p1 -i ../pylama-pyflakes-2.5.patch
}

build() {
  cd $pkgname-$pkgver
  python setup.py build
}

check() {
  cd $pkgname-$pkgver
  python setup.py install --root="$PWD/tmp_install" --optimize=1
  local python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
  PYTHONPATH="$PWD/tmp_install/usr/lib/python$python_version/site-packages:$PYTHONPATH:$PWD/tests" py.test --pylama pylama
  PYTHONPATH="$PWD/tmp_install/usr/lib/python$python_version/site-packages:$PYTHONPATH:$PWD/tests" py.test tests --deselect tests/test_config.py::test_ignore_select \
                                                                                                     --deselect tests/test_linters.py::test_eradicate
}

package() {
  cd $pkgname-$pkgver
  python setup.py install --root="$pkgdir/" --optimize=1

  mv "$pkgdir"/usr/lib/python3.11/site-packages/{,pylama/}tests
}
